package vn.co.thn.android.videohot.common;

import vn.co.thn.android.serviceconnect.callback.RequestError;
import vn.co.thn.android.serviceconnect.request.RequestService;
import vn.co.thn.android.videohot.VHApp;
import vn.co.thn.android.videohot.VHConstants;
import android.content.Intent;
import android.widget.Toast;

import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayer.Provider;

public abstract class VHCommonYouTubeActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener ,RequestError{
	private static final int RECOVERY_DIALOG_REQUEST = 1;
	protected RequestService mRequestService=new RequestService(VHApp.getInstance());
	@Override
	public void onInitializationFailure(Provider provider, YouTubeInitializationResult errorReason) {
		// TODO Auto-generated method stub
		if (errorReason.isUserRecoverableError()) {
			errorReason.getErrorDialog(this, RECOVERY_DIALOG_REQUEST).show();
		} else {
			String errorMessage = "error play";
			Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (requestCode == RECOVERY_DIALOG_REQUEST) {
			// Retry initialization if user performed a recovery action
			getYouTubePlayerProvider().initialize(VHConstants.API_KEY, this);
		}
	}

	@Override
	public void onInitializationSuccess(Provider arg0, YouTubePlayer arg1, boolean arg2) {
		// TODO Auto-generated method stub

	}

	protected abstract YouTubePlayer.Provider getYouTubePlayerProvider();
}
